package com.cnpc.bds.sdk.sink.kafka.executor;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

public class EventLoopFactory implements ThreadFactory {

    private final AtomicInteger threadId = new AtomicInteger(0);

    private final String prefix;

    public EventLoopFactory(String prefix) {
        this.prefix = prefix;
    }

    @Override
    public Thread newThread(Runnable r) {
        return new Thread(r, prefix + "-" + threadId.getAndIncrement());
    }

    public EventLoop wrapAndStart(EventLoop r) {
        newThread(r).start();
        return r;
    }

}
